﻿using DAL;
using SurveillancePro.Base.ViewModels;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PersonnelLocationModule.Models
{
    /// <summary>
    /// 人员属性
    /// </summary>
    public class EmployeeModel : ViewModelBase, IEquatable<EmployeeModel>
    {
        #region Private Fields

        private static DataSet _dsTreeNode;
        private static ISSDal _dataOperation = new ISSDal();
        private DataRow _row;

        #endregion

        #region Constructor

        /// <summary>
        /// 只需要表结构的数据集
        /// </summary>
        public EmployeeModel()
        {
            if (_dsTreeNode == null ||
                _dsTreeNode.Tables.Count <= 0)
                throw new Exception("数据库异常！");

            _row = _dsTreeNode.Tables[0].NewRow(); // 添加一个新数据行
        }

        /// <summary>
        /// 选中的指定行
        /// </summary>
        /// <param name="row"></param>
        public EmployeeModel(DataRow row)
        {
            this._row = row;
        }

        #endregion

        #region IEquatable Members

        public bool Equals(EmployeeModel obj)
        {
            return this._row["EmpID"].ToString() == obj._row["EmpID"].ToString();
        }

        #endregion

        #region Public Properties

        #region 与界面绑定的属性

        private string _empEnterTime;
        /// <summary>
        /// 进入区域站点时间
        /// </summary>
        public string EmpEnterTime
        {
            get { return _empEnterTime; }
            set
            {
                if (_empEnterTime == value) return;
                _empEnterTime = value;
                base.OnPropertyChanged("EmpEnterTime");
            }
        }

        #endregion

        /// <summary>
        /// ID
        /// </summary>
        [System.ComponentModel.DataAnnotations.Key]
        public string EmpID
        {
            get { return _row["EmpID"].ToString(); }
            set
            {
                if (value == _row["EmpID"].ToString()) return;
                _row["EmpID"] = value;
                base.OnPropertyChanged("EmpID");
            }
        }

        /// <summary>
        /// Name
        /// </summary>
        public string EmpName
        {
            get { return _row["EmpName"].ToString(); }
            set
            {
                if (value == _row["EmpName"].ToString()) return;
                _row["EmpName"] = value;
                base.OnPropertyChanged("EmpName");
            }
        }

        /// <summary>
        /// Sex
        /// </summary>
        public string EmpSex
        {
            get { return _row["EmpSex"].ToString(); }
            set
            {
                if (value == _row["EmpSex"].ToString()) return;
                _row["EmpSex"] = value;
                base.OnPropertyChanged("EmpSex");
            }
        }

        /// <summary>
        /// Nation
        /// </summary>
        public string EmpNation
        {
            get { return _row["EmpNation"].ToString(); }
            set
            {
                if (value == _row["EmpNation"].ToString()) return;
                _row["EmpNation"] = value;
                base.OnPropertyChanged("EmpNation");
            }
        }

        /// <summary>
        /// ID Card
        /// </summary>
        public string IDCard
        {
            get { return _row["IDCard"].ToString(); }
            set
            {
                if (value == _row["IDCard"].ToString()) return;
                _row["IDCard"] = value;
                base.OnPropertyChanged("IDCard");
            }
        }

        /// <summary>
        /// Home Address
        /// </summary>
        public string HomeAddress
        {
            get { return _row["HomeAddress"].ToString(); }
            set
            {
                if (value == _row["HomeAddress"].ToString()) return;
                _row["HomeAddress"] = value;
                base.OnPropertyChanged("HomeAddress");
            }
        }

        /// <summary>
        /// Phone
        /// </summary>
        public string EmpPhone
        {
            get { return _row["EmpPhone"].ToString(); }
            set
            {
                if (value == _row["EmpPhone"].ToString()) return;
                _row["EmpPhone"] = value;
                base.OnPropertyChanged("EmpPhone");
            }
        }

        /// <summary>
        /// Job
        /// </summary>
        public string EmpJob
        {
            get { return _row["EmpJob"].ToString(); }
            set
            {
                if (value == _row["EmpJob"].ToString()) return;
                _row["EmpJob"] = value;
                base.OnPropertyChanged("EmpJob");
            }
        }

        /// <summary>
        /// Dept Name
        /// </summary>
        public string DeptName
        {
            get { return _row["DeptName"].ToString(); }
            set
            {
                if (value == _row["DeptName"].ToString()) return;
                _row["DeptName"] = value;
                base.OnPropertyChanged("DeptName");
            }
        }

        /// <summary>
        /// Remark
        /// </summary>
        public string Remark
        {
            get { return _row["Remark"].ToString(); }
            set
            {
                if (value == _row["Remark"].ToString()) return;
                _row["Remark"] = value;
                base.OnPropertyChanged("Remark");
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// 加载全部【Static 方法】
        /// </summary>
        /// <returns></returns>
        public static DataRowCollection Load_All()
        {
            if (_dataOperation == null)
                return null;

            _dsTreeNode = _dataOperation.GetDataSet(ISSDal.QUERY_GET_ALLEMPLOYEEDATA,
                null, "db_VWMSConnectionString", string.Format("{0}.exe", System.Windows.Forms.Application.ProductName));

            if (_dsTreeNode != null && _dsTreeNode.Tables.Count > 0)
                return _dsTreeNode.Tables[0].Rows;
            else
                return null;
        }

        #endregion
    }
}
